package Cy.Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Cy.DAO.EvaluateDAO;
import Entity.Commodity;
import Entity.Users;
import Factory.EvaluateFactory;
import extend.Evaluatedelete;

/**
 * Servlet implementation class SelectEvaluateServlet
 */
@WebServlet("/selectevaluatezhongzhuan")
public class SelectEvaluatezhongzhuanServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private EvaluateDAO evaluateDAO = EvaluateFactory.createDAO();
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int curpage = Integer.parseInt(request.getParameter("curpage"));
		int pagesize = Integer.parseInt(request.getParameter("pagesize"));
		int cid = Integer.parseInt(request.getParameter("cid"));
		if(cid!=0){
			List<Evaluatedelete> list = evaluateDAO.selectvaluatecommodity(cid,curpage,pagesize);
			request.setAttribute("list", list);
			int total = evaluateDAO.countevaluatecommodity(cid);
			request.setAttribute("total", total);
			request.setAttribute("cid", cid);
		}else{
			int uid = Integer.parseInt(request.getParameter("uid"));
			if(uid!=0){
				List<Evaluatedelete> list = evaluateDAO.selectvaluateuser(uid, curpage, pagesize);
				request.setAttribute("list",list);
				int total = evaluateDAO.countevaluateuser(uid);
				request.setAttribute("total", total);
				request.setAttribute("uid", uid);
			}else{
				String estar = request.getParameter("estar");
				if(estar.equals("0")){
					List<Evaluatedelete> list = evaluateDAO.selectdeleteevaluate(curpage,pagesize);
					request.setAttribute("list", list);
					int total = evaluateDAO.countevaluate();
					request.setAttribute("total", total);
				}else{
					List<Evaluatedelete> list = evaluateDAO.selectvaluatestar(estar, curpage, pagesize);
					request.setAttribute("list", list);
					int total = evaluateDAO.countevaluatstar(estar);
					request.setAttribute("total", total);
					request.setAttribute("estar", estar);
				}
			}
		}
		List<Commodity> comlist = evaluateDAO.selectcommodityevaluate();
		List<Users> userlist = evaluateDAO.selectuserevaluate();
		request.setAttribute("comlist", comlist);
		request.setAttribute("userlist", userlist);
		request.getRequestDispatcher("selectEvaluate1.jsp?curpage="+curpage+"&pagesize=10").forward(request, response);
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}
}
